//package xyz.kail.demo.prometheus.boot.config;
//
//import com.codahale.metrics.MetricRegistry;
//import io.prometheus.client.CollectorRegistry;
//import io.prometheus.client.dropwizard.DropwizardExports;
//import io.prometheus.client.exporter.PushGateway;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.util.concurrent.Executors;
//import java.util.concurrent.TimeUnit;
//
//@Component
//public class PrometheusConfig {
//
//    @Autowired
//    MetricRegistry dropwizardRegistry;
//
//    @Value("${spring.application.name}")
//    String applicationName;
//
//    @Value("${prometheus.pushgateway.host}")
//    String pushHost;
//
//    @Value("${prometheus.pushgateway.intervalInMillis:10000}")
//    long intervalInMillis;
//
//    private final CollectorRegistry prometheusRegistry = new CollectorRegistry();
//
//    @PostConstruct
//    public void initialize() {
//        DropwizardExports prometheus = new DropwizardExports(dropwizardRegistry);
//        prometheus.register(prometheusRegistry);
//
//        PushGateway prometheusPush = new PushGateway(pushHost);
//
//        Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> {
//            try {
//                prometheus.collect();
//                prometheusPush.push(prometheusRegistry, applicationName);
//            } catch (Exception e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }
//        }, 5000, intervalInMillis, TimeUnit.MILLISECONDS);
//    }
//}
